/**
 * @Description: 路由跳转
 * @author bev
 * @date 2019/9/25
 * @time 13:43
 */

export const NavigateTo = ({ url, query }) => {
  if (query) {
    url += "?";
    Object.entries(query).forEach(([key, value]) => {
      url += `${key}=${value}&`;
    });
  }
  return uni.navigateTo({
    url,
    animationType: "pop-in",
    animationDuration: 200
  });
};

export const NavigateBack = (delta = 1) => {
  return uni.navigateBack({
    delta,
    animationType: "pop-out",
    animationDuration: 200
  });
};

export const RedirectTo = ({ url, query }) => {
  if (query) {
    url += "?";
    Object.entries(query).forEach(([key, value]) => {
      url += `${key}=${value}&`;
    });
  }
  return uni.redirectTo({
    url
  });
};

export const ReLaunch = ({ url }) => {
  return uni.reLaunch({
    url
  });
};

export const SwitchTab = ({ url }) => {
  return uni.switchTab({
    url
  });
};
